package com.booksys.examination.controller;

import com.booksys.examination.entity.User;
import com.booksys.examination.service.LoginUserService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author Administrator
 * @date 2019-08-14 11:32
 */
@Controller
public class LoginUserController {
    @Resource
    private LoginUserService loginUserService;
    @PostMapping("/doLogin")
    public String doLogin(String loginName,
                          String loginPassword,
                          Map<String,Object> map,
                          HttpSession session){
        User user = loginUserService.findUserWithNmPw(loginName, loginPassword);

        if (StringUtils.isEmpty(user)){
            map.put("msg","用户名或密码错误");
            return "login";
        }else {
            session.setAttribute("user",user);
            return "redirect:/pagination";
        }
    }
}
